﻿using System;

namespace cSharpHomework2_5
{
    class Program
    {
        static void Main(string[] args)
        {
            Random rd = new Random();
            int sumArea = 0;
            ShapeFactory shapeFactory = new ShapeFactory();
            for (int i = 1; i <= 10; i++)
            {
                shape a = shapeFactory.CreatShape(rd.Next(0, 2));
                sumArea += a.area;

            }
            Console.WriteLine(sumArea);
        }
        public interface shape
        {

            int area { get; }

            public double GetArea();
            public bool IsValid();
        }

        class rectangle : shape
        {
            Random a = new Random();

            public rectangle()
            {
                this.chang = a.Next(1, 10);
                this.kuan = a.Next(1, 10);
            }


            int chang { get; set; }
            int kuan { get; set; }

            public int area => chang * kuan;

            public bool IsValid()
            {
                if (chang < 0 || kuan < 0)
                {
                    return false;
                }
                return true;
            }

            public double GetArea()
            {

                return chang * kuan;
            }
        }

        class Square : shape
        {
            Random ran = new Random();
            public Square()
            {
                this.a = ran.Next(1, 10);
            }

            int a { get; set; }
            public int area => a * a;

            double shape.GetArea()
            {
                return a * a;
            }

            bool shape.IsValid()
            {
                if (a < 0) { return false; } else return true;
            }
        }

        class triangle : shape
        {
            Random ran = new Random();

            public triangle()
            {
                this.kuan = ran.Next(1, 10);
                this.gao = ran.Next(1, 10);
            }

            int kuan { get; set; }
            int gao { get; set; }
            public int area => kuan * gao / 2;

            public double GetArea()
            {
                return kuan * gao / 2;
            }

            public bool IsValid()
            {

                if (kuan < 0 || gao < 0)
                {
                    return false;
                }
                else return true;
            }
        }

        class ShapeFactory
        {

            public shape CreatShape(int i)
            {
                shape a = null;
                switch (i)
                {
                    case 0:
                        a = new rectangle();
                        break;
                    case 1:
                        a = new Square();
                        break;
                    case 2:
                        a = new triangle();
                        break;

                }
                return a;
            }
        }
    }
}
